<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title>采购项目</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>采购项目管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">采购项目管理</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">               
                <div class="input">
                    <div class="textalign1">项目名称：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="name" name="name" placeholder="项目名称" />
                    </div>
                    
                    <div class="textalign1">项目编号：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="projCode" name="projCode" placeholder="项目编号" />
                    </div>
                    
                    <!-- <div class="textalign1">项目状态：</div>
                    <div class="boxinput">
                        <select id="status" name="status" class="textinput">
                            <option value="">请选择</option>
                            <option value="1">启用</option>
                            <option value="0">停用</option>
                        </select>
                    </div> -->
                    <div class="textalign" >
                        <button  id="selectSerch"  type="button" onclick="gridSerch();" class="btn btn-success btn-sm"> <spring:message code="message.button.seachSpacing"/> </button>
                    </div>
               </div>
                
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <%-- <div class=" box box-warning bottongroup">
            <a href="toPurEdit.html" class="btn btn-default btn-sm"><spring:message code="message.button.addSpacing"/></a>
        </div> --%>
    </section>
    <form action="${ctx}/bidProject/toAddedBidPurProjectCompsList.html" method="post" id="Form">
    <input type="hidden" name="projId" id="projId">
    <input type="hidden" name=projName id="newname">
    </form>
     <form action="${ctx}/bidProject/toPurHospList.html" method="post" id="FormAddhosp">
    <input type="hidden" name="projIdAddhosp" id="projIdAddhosp">
    <input type="hidden" name="proName" id="proName">
    </form>
      <form action="${ctx}/bidProject/toPurCompList.html" method="post" id="FormAddcomp">
    <input type="hidden" name="projIdAddcomp" id="projIdAddcomp">
    <input type="hidden" name="compName" id="compName">
    </form>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    
        //加载页面光标在名字框内，位于第一个
        $("#name").focus();
    
        //绑定回车    id="selectSerch"  
        $('#name,#projCode,#status').bind('keydown', function(event) {
            if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
		            $('#selectSerch').click();
		        }
		    }); 
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "${pageContext.request.contextPath}/bidProject/getPurDataList.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 255,
                shrinkToFit:true,
                colNames: [
                           '操作',
                           'projId', 
                           '项目编号', 
                           '项目名称', 
                           '项目类型',
                           '创建日期',
                           '采购开始日期',
                           '采购结束日期',
                           '项目状态', 
                           '药品数', 
                           '医疗机构数',
                           '配送企业数'
                           ],
                colModel: [
                    { name: 'operate', width: 80, align: 'center' ,hidden:false,sortable: false,
                    	formatter: function (val, opts, rowdata) {
                    		var str ="";
                    		 if(rowdata.projCat == "备案采购"){
                    			
                    		}else{
                    			if (rowdata.status=="启用"){
                                    str += "<a href='${ctx}/bidProject/toPurCompList.html?projIdAddcomp="+rowdata.projId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -60px -100px' class='opIcon' title='添加配送企业'></a>";
                                    //str += "<a href='javascript:void(0)' onclick=\"switchStatus('"+rowdata.projId+"','0')\"  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -40px 0px' class='opIcon' title='停用'></a>";
                                    str += "<a href='${ctx}/bidProject/toPurHospList.html?projIdAddhosp="+rowdata.projId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -80px -20px' class='opIcon' title='添加医疗机构'></a>";
                                } else if (rowdata.status=="停用") {
                                    //str += "<a href='javascript:void(0)' onclick=\"switchStatus('"+rowdata.projId+"','1')\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -60px 0px' class='opIcon' title='启用'></a>";
                                }
                    		}
                    		
                    		return str;
                    	}	
                    },
                    { name: 'projId', key:true,hidden:true,width: 40, align: 'center' ,sortable: false},
                    { name: 'projCode', width: 80, align: 'center' ,sortable: false},
                    { name: 'name', width: 200, align: 'center' ,sortable: false},
                    { name: 'projCat', width: 90,hidden:true, align: 'center' ,sortable: false},
                    { name: 'createDatetime', width: 80, align: 'center' ,sortable: false},
                    { name: 'starttime', width: 80, align: 'center' ,sortable: false},
                    { name: 'endtime', width: 80, align: 'center' ,sortable: false},
                    { name: 'status', width: 60, hidden:true,align: 'center' ,sortable: false},
                    { name: 'drugCount', width: 70, align: 'center' ,sortable: false,formatter: function (val, opts, rowdata) {return "<a href=\"toAddedBidPurProjectDrugsList.html?projId="+rowdata.projId+ encodeURI(encodeURI("&projName="+rowdata.name))+"\">"+val+"</a>";}},
                    { name: 'hospCount', width: 75, align: 'center' ,sortable: false,formatter: function (val, opts, rowdata) {return "<a href=\"toHospEditList.html?projId="+rowdata.projId+ encodeURI(encodeURI("&projName="+rowdata.name))+"\">"+val+"</a>";}},
                    { name: 'delCompCount', width: 75, align: 'center' ,sortable: false,formatter: function (val, opts, rowdata) {return "<a href=\"javascript:getForm('"+rowdata.projId+"','"+ rowdata.name+"');\">"+val+"</a>";}}
                
                ],
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                caption: "采购项目列表",
              //序号宽度自动变化
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
                jsonReader: {
                    repeatitems: false  
                },
                loadComplete: function (data) { //完成服务器请求后，回调函数
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
			$("#gridlist").jqGrid("setGridHeight", create());

        });
        function gridSerch() {
        	var projCode = $.trim($("#projCode").val());
        	var name = $.trim($("#name").val());
        	var status = $("#status").val();
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"projCode":projCode,
    	        		"name":name,
    	        		"status":status}
    	    }).trigger("reloadGrid"); //重新载入  
    	}
        function toAddhosp(projId,name){
        	$("#projIdAddhosp").val(projId);
        	$("#proName").val(name);
        	$("#FormAddhosp").submit();
        }
        function getForm(projId,name){
        	$("#projId").val(projId);
        	$("#newname").val(name);
        	$("#Form").submit();
        }
        function toAddComp(projId,name){
        	$("#projIdAddcomp").val(projId);
        	$("#compName").val(name);
        	$("#FormAddcomp").submit();
        }
        function switchStatus(id, status) {
        	var msg = "";
        	if (status == 1){
        		msg = "启用";
        	} else if (status == 0){
        		msg = "停用";
        	}
        	 $.HN.message.confirm('确定'+msg+'吗？', '', '').on(function (e) {
        		 if(e){
        			 $.post("${pageContext.request.contextPath}/bidProject/switchPurStatus.html", {
        				 projId : id,
        				 status : status
        	    		}, function(result) {
        	    			
        	    			if (result == "success") {
        	    				gridSerch();
        	    				$.HN.message.alert("操作成功！", "消息", "success");
        	    			} else {
        	    				$.HN.message.alert("操作失败！", "消息", "error");
        	    			}
        	    		}, "json")
        		 }
        		 
        	 });
    	}
    </script>
</body>
</html>